package com.example.gcmtest;

import static java.lang.Math.*;

public class CalcDistance {
	/*コンストラクタ*/
	public CalcDistance() {
	}
	/*コーナーまでの距離算出用メソッド*/
	public double distance_atob(double lat1, double lon1, double lat2, double lon2, char unit) {
		double theta = lon1 - lon2;
        double dist = sin(deg2rad(lat1)) * sin(deg2rad(lat2)) +  cos(deg2rad(lat1)) * cos(deg2rad(lat2)) * cos(deg2rad(theta));

        dist = acos(dist);
        dist = rad2deg(dist);

        double miles = dist * 60 * 1.1515;
        switch (unit){
        case 'K':
        	return (miles * 1.609344)*1000;
        case 'N':
        	return (miles * 0.8684);
        case 'M':
        	default:
        	return miles;
        }
    }
    private static double rad2deg(double radian) {
    	return radian * (180f / Math.PI);
    }
    public static double deg2rad(double degrees) {
    	return degrees * (Math.PI / 180f);
    }
}

